package solved;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	butter
*/
public class butter {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("butter.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"butter.out")));
		new butter().solve(f, out);
		out.close();
		System.exit(0);
	}
	
	private final static int INF = 225*800+1;
	
	private void solve(BufferedReader f, PrintWriter out) throws IOException {
		int[] a = read(f, 3);
		int N = a[0];
		int P = a[1];
		int C = a[2];
		
		int[] cow = new int[N];
		for (int i=0; i<N; i++) cow[i] = read(f);
		
		int[][] path = new int[P][P];
		for (int i=0; i<P; i++) {
			for (int j=0; j<P; j++) {
				path[i][j] = i==j? 0 : INF;
			}
		}
		
		for (int i=0; i<C; i++) {
			a = read(f, 3);
			path[a[0]-1][a[1]-1] = a[2];
			path[a[1]-1][a[0]-1] = a[2];
		}
		
		for (int k=0; k<P; k++) {
			for (int i=0; i<P; i++) {
				for (int j=0; j<P; j++) {
					path[i][j] = Math.min(path[i][j], path[i][k] + path[k][j]);
				}
			}
		}
		
		int min = Integer.MAX_VALUE;
		for (int i=0; i<P; i++) {
			int cost = 0;
			for (int j=0; j<N; j++) {
				cost += path[cow[j]-1][i];
			}
			if (cost < min) min = cost;
		}
		
		out.println(min);
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
